/*********************************************************
          File Name:16.47.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun 20 Dec 2015 01:38:38 PM CST
**********************************************************/

#include <iostream>

using std::cout;
using std::endl;

template<typename Func, typename T1, typename T2>
void flip(Func f, T1&& t1, T2&& t2)
{
        f(std::forward<T1>(t2), std::forward<T2>(t1));
}

void v1(int i, int j)
{
        cout << i << "\t" << j << endl;
}

void v2(int &i, int j)
{
        cout << ++i << "\t" << ++j << endl;
}

void v3(int &&i, int j)
{
        cout << ++i << "\t" << ++j << endl;
}

void v4(int i, int &j)
{
        cout << ++i << "\t" << ++j << endl;
}

void v5(int i, int &&j)
{
        cout << ++i << "\t" << ++j << endl;
}

void v6(int &i, int &j)
{
        cout << ++i << "\t" << ++j << endl;
}

void v7(int &&i, int &&j)
{
        cout << ++i << "\t" << ++j << endl;
}

int main()
{
        {
                int i = 0, j = 0;
                flip(v1,  i, j);
                cout << "=> " << i << "\t" << j << endl;
        }
        {
                int i = 0, j = 0;
                flip(v2, i, j);
                cout << "=> " << i << "\t" << j << endl;
        }
        {
                int j = 0;
                flip(v3, 0, j);
                cout << "=> " << 0 << "\t" << j << endl;
        }
        {
                int i = 0, j = 0;
                flip(v4, i, j);
                cout << "=> " << i << "\t" << j << endl;
        }
        {
                int i = 0;
                flip(v5, i, 0);
                cout << "=> " << i << "\t" << 0 << endl;
        }
        {
                int i = 0, j = 0;
                flip(v6, i, j);
                cout << "=> " << i << "\t" << j << endl;
        }
        flip(v7, 1, 2);
        cout << "=> " << 1 << "\t" << 2 << endl;

        return 0;
}
